package com.braveman.im.ui.activity.message;

import android.graphics.Color;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;

import com.braveman.im.R;
import com.braveman.im.bean.ComplainBean;
import com.braveman.im.ui.adapter.CompanyCheckAdapter;
import com.braveman.im.utils.UtilsStyle;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ht.baselibs.ui.base.BaseActivity;
import com.vondear.rxtools.RxBarTool;

import java.util.ArrayList;
import java.util.List;

public class CompanyCheckActivity extends BaseActivity implements BaseQuickAdapter.RequestLoadMoreListener, SwipeRefreshLayout.OnRefreshListener {
    private List<ComplainBean> list = new ArrayList();
    private CompanyCheckAdapter checkAdapter;
    private RecyclerView mListView;
    private SwipeRefreshLayout mSwipeRefreshLayout;


    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("审核").setLeftBtnIcon(R.mipmap.back_black);
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_company_check;
    }

    @Override
    protected void initChildView() {
        mListView = (RecyclerView) findViewById(R.id.rv_list);
        mListView.setLayoutManager(new LinearLayoutManager(this));
        ComplainBean accountBean = new ComplainBean();
        //accountBean.text = "11111";
        list.add(accountBean);
        list.add(accountBean);
        list.add(accountBean);
        list.add(accountBean);
        list.add(accountBean);
        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeLayout);
        mSwipeRefreshLayout.setOnRefreshListener(this);
        mSwipeRefreshLayout.setColorSchemeColors(Color.rgb(47, 223, 189));
    }

    @Override
    protected void initChildData() {
        checkAdapter = new CompanyCheckAdapter(R.layout.item_company_check, list);
        mListView.setAdapter(checkAdapter);

    }

    @Override
    protected void setChildViewListener() {

        mListView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
            @Override
            public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
                return false;
            }

            @Override
            public void onTouchEvent(RecyclerView rv, MotionEvent e) {

            }

            @Override
            public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

            }
        });

    }

    @Override
    public void onRefresh() {
        checkAdapter.setEnableLoadMore(false);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mSwipeRefreshLayout.setRefreshing(false);
            }
        }, 1000);
    }

    @Override
    public void onLoadMoreRequested() {
        mSwipeRefreshLayout.setEnabled(false);
        if (checkAdapter.getData().size() < 5) {
            checkAdapter.loadMoreEnd(true);
        } else {

            mSwipeRefreshLayout.setEnabled(true);
        }
    }
}
